package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.config.AlipayTemplate;
import com.atguigu.gulimall.order.service.OmsOrderService;
import com.atguigu.gulimall.order.vo.PayVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ming
 * @create 2022/5/12
 * @description:
 */
@Controller
@Slf4j
public class PayWebController {
    @Autowired
    private AlipayTemplate aipayTemplate;
    @Autowired
    private OmsOrderService orderService;

    /**
     * 支付成功以后跳到用户列表页
     * @param orderSn
     * @return
     * @throws AlipayApiException
     */
    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")
    public String payOrder(@RequestParam("orderSn")String orderSn) throws AlipayApiException {

        /**         PayVo payVo = new PayVo();
         *          payVo.setBody();       //订单的备注
         *         payVo.setOut_trade_no(); //订单号
         *         payVo.setSubject(); //订单的主题
         *         payVo.setTotal_amount();//金额
         *         aipayTemplate.pay(payVo);
         */
        PayVo payVo = orderService.getOrderPay(orderSn);
        log.info("payVo:{}",payVo);
        //支付宝返回的是一个页面,将此页面直接交给浏览器
        String pay = aipayTemplate.pay(payVo);
        return pay;
    }
    
}
